package http.client;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;

public class HttpClient {

    public static void main(String[] args){
        String request ="";
        String inputLine = "";
        String result = "";
    try {
        URL url = new URL("http://127.0.0.1:8081/auth/api/keepCourse?memberId=1111&relateId=22220&relateType=1&operateType=1");

        URLConnection connection = url.openConnection();
        HttpURLConnection httpconn = (HttpURLConnection) connection;
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        bout.write(request.getBytes());
        byte[] b = bout.toByteArray();
        httpconn.setRequestProperty("accept", "*/*");
        httpconn.setRequestProperty("Content-Length", String.valueOf(b.length));
        httpconn.setRequestProperty("Content-Type", "text/xml; charset=utf8");
        httpconn.setRequestProperty("user-agent",
                "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
        httpconn.setRequestMethod("POST");
        httpconn.setDoInput(true);
        httpconn.setDoOutput(true);

        OutputStream out = httpconn.getOutputStream();
        out.write(b);
        out.close();

        InputStreamReader isr = new InputStreamReader(httpconn.getInputStream());
        BufferedReader in = new BufferedReader(isr);
        
        while (null != (inputLine = in.readLine())) {
            result += inputLine;
        }
        System.out.println("result:" + result);
    } catch (Exception e) {
       e.printStackTrace();
    }
    }
}
